package com.adbj.sychronizedtest;

public class StaticMethodTest implements Runnable{

    static int count=0;

    @Override
    public synchronized void run() {
        increaseCount();
    }

    //静态方法是不属于当前实例的，而是属性类的 锁就是类的class对象锁
    private synchronized static void increaseCount() {
        for (int i = 0; i < 5; i++) {
            System.out.println(Thread.currentThread().getName() + ":" + count++);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        StaticMethodTest syncTest1=new StaticMethodTest();
        StaticMethodTest syncTest2=new StaticMethodTest();
        Thread thread1=new Thread(syncTest1,"thread1");
        Thread thread2=new Thread(syncTest2,"thread2");
        thread1.start();
        thread2.start();
    }

}
